home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / frntsdk1.cpt / Frontier SDK 1.0 ƒ / Applet Toolkit / about.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-28  |  6.2 KB  |  370 lines

  1.  
  2. /*⌐ Copyright 1988-1991 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletinternal.h"
  6. #include "ops.h"
  7. #include "quickdraw.h"
  8. #include "appletmain.h"
  9. #include "about.h"
  10.  
  11.  
  12. #ifdef MPWC
  13.  
  14. #include <toolutils.h>
  15. #include <osevents.h>
  16.  
  17. #endif
  18.  
  19.  
  20.  
  21. #define aboutlistnumber 128
  22.  
  23. #define zoomfixer 65536L
  24.  
  25. #define zoomsteps 16
  26.  
  27. Fixed zoomfract;
  28.  
  29. WindowPtr aboutwindow = nil;
  30.  
  31.  
  32.  
  33.  
  34.  
  35. static short zoomblend (short i1, short i2) {
  36.  
  37.     Fixed smallFix,bigFix,tempFix;
  38.  
  39.     smallFix = zoomfixer * i1;
  40.     
  41.     bigFix = zoomfixer * i2;
  42.     
  43.     tempFix = FixMul (zoomfract, bigFix) + FixMul (zoomfixer-zoomfract, smallFix);
  44.     
  45.     return (FixRound (tempFix));
  46.     } /*zoomblend*/
  47.     
  48.  
  49. static void zoomrect (Rect *smallrect, Rect *bigrect, Boolean zoomup) {
  50.  
  51.     Fixed factor;
  52.     Rect rect1,rect2,rect3,rect4;
  53.     GrafPtr savePort,deskPort;
  54.     short i;
  55.     
  56.     GetPort (&savePort);
  57.     
  58.     OpenPort (deskPort = (GrafPtr) NewPtr (sizeof (GrafPort)));
  59.     
  60.     InitPort (deskPort);
  61.     
  62.     SetPort (deskPort);
  63.     
  64.     PenPat (quickdrawglobal (gray));
  65.     
  66.     PenMode (notPatXor);
  67.     
  68.     if (zoomup) {
  69.     
  70.         rect1 = *smallrect;
  71.         
  72.         factor = FixRatio(6,5);
  73.         
  74.         zoomfract = FixRatio(541,10000);
  75.         }
  76.     else {
  77.         rect1 = *bigrect;
  78.         
  79.         factor = FixRatio(5,6);
  80.         
  81.         zoomfract = zoomfixer;
  82.         }
  83.         
  84.     rect2 = rect1;
  85.     
  86.     rect3 = rect1;
  87.     
  88.     FrameRect (&rect1);
  89.     
  90.     for (i = 1; i<= zoomsteps; i++) {
  91.     
  92.         rect4.left = zoomblend (smallrect->left, bigrect->left);
  93.         
  94.         rect4.right = zoomblend (smallrect->right, bigrect->right);
  95.         
  96.         rect4.top = zoomblend (smallrect->top, bigrect->top);
  97.         
  98.         rect4.bottom = zoomblend (smallrect->bottom, bigrect->bottom);
  99.         
  100.         FrameRect (&rect4);
  101.         
  102.         FrameRect (&rect1);
  103.         
  104.         rect1 = rect2;
  105.         
  106.         rect2 = rect3;
  107.         
  108.         rect3 = rect4;
  109.          
  110.         zoomfract = FixMul (zoomfract,factor);
  111.         } /*for*/
  112.         
  113.     FrameRect (&rect1);
  114.     
  115.     FrameRect (&rect2);
  116.     
  117.     FrameRect (&rect3);
  118.     
  119.     ClosePort (deskPort);
  120.     
  121.     DisposPtr ((Ptr)deskPort);
  122.     
  123.     PenNormal ();
  124.     
  125.     SetPort (savePort);
  126.     } /*zoomrect*/
  127.     
  128.     
  129. static void zoomport (WindowPtr w, boolean flup) {
  130.  
  131.     /*
  132.     Zooms the window referenced by "w" either from an inivisible
  133.     state to a visible state, or vice versa.  Pass true in the "flup"
  134.     boolean parameter to zoom a window to open, an false to zoom
  135.     it close.  The WindowPtr must have already been created elsewhere,
  136.     and zooming the window invisible only hides the window, it does
  137.     not destroy the WindowPtr data.
  138.     */
  139.     
  140.     Rect r1, r2, r3;
  141.  
  142.     SetPort (w);
  143.     
  144.     SetRect (&r1, 0, 20, 0, 20);
  145.     
  146.     r3 = (*w).portRect;
  147.     
  148.     r2 = r3;
  149.     
  150.     InsetRect (&r2, (r3.right - r3.left + 20) / 2, (r3.bottom - r3.top + 20) / 2);
  151.  
  152.     localtoglobalrect (&r2);
  153.     
  154.     localtoglobalrect (&r3);
  155.  
  156.     if (flup) {
  157.     
  158.         zoomrect (&r1, &r2, true);
  159.         
  160.         zoomrect (&r2, &r3, true);
  161.         
  162.         ShowWindow (w);
  163.         
  164.         SetPort (w);
  165.         }
  166.     else {
  167.         HideWindow (w);
  168.         
  169.         zoomrect (&r2, &r3, false);
  170.         
  171.         zoomrect (&r1, &r2, false);
  172.         }
  173.     } /*zoomport*/
  174.     
  175.     
  176. #define doline(x)\
  177.                                                                             \
  178.     MoveTo (r.left + (r.right - r.left - StringWidth (x)) / 2, linev);        \
  179.                                                                             \
  180.     DrawString (x);                                                            \
  181.                                                                             \
  182.     linev += lineinc;
  183.  
  184.  
  185. static void drawabout (WindowPtr w) {
  186.     
  187.     register short i;
  188.     register short linev = 24;
  189.     register short lineinc = 14;
  190.     bigstring lines [6];
  191.     Rect r;
  192.     
  193.     for (i = 0; i <= 5; i++)    
  194.         GetIndString (lines [i], aboutlistnumber, i + 1);
  195.     
  196.     r = (*w).portRect;
  197.     
  198.     InsetRect (&r, 4, 4);
  199.     
  200.     TextFont (systemFont);
  201.     
  202.     TextSize (12);
  203.     
  204.     doline (lines [0]);
  205.     
  206.     TextFont (geneva);
  207.     
  208.     TextSize (9);
  209.     
  210.     doline (lines [1]);
  211.     
  212.     linev += lineinc; /*skip a line*/
  213.     
  214.     doline (lines [2]);
  215.     
  216.     doline (lines [3]);
  217.     
  218.     MoveTo (r.left + 4, r.bottom - 6);
  219.     
  220.     DrawString (lines [4]);
  221.     
  222.     MoveTo (r.right - StringWidth (lines [5]) - 4, r.bottom - 6);
  223.     
  224.     DrawString (lines [5]);
  225.     } /*drawabout*/
  226.     
  227.  
  228. void openabout (Boolean flzoom) { /*can also be called to implement the splash window*/
  229.  
  230.     Rect r;
  231.     
  232.     SetRect (&r, 0, 0, 340, 120);
  233.     
  234.     pushmacport (aboutwindow = NewWindow (nil, &r, (ConstStr255Param)"\p", false, altDBoxProc, (WindowPtr) -1, false, 0));
  235.         
  236.     centerwindow ((DialogPtr) aboutwindow, quickdrawglobal (screenBits).bounds);
  237.     
  238.     if (flzoom)
  239.         zoomport (aboutwindow, true);
  240.     else
  241.         ShowWindow (aboutwindow);
  242.     
  243.     drawabout (aboutwindow);
  244.     } /*openabout*/
  245.     
  246.     
  247. void closeabout (Boolean flzoom) {
  248.  
  249.     if (aboutwindow != nil) {
  250.     
  251.         HideWindow (aboutwindow);
  252.         
  253.         if (flzoom)
  254.             zoomport (aboutwindow, false);
  255.         else
  256.             HideWindow (aboutwindow);
  257.         
  258.         DisposeWindow (aboutwindow);
  259.         
  260.         aboutwindow = nil;
  261.         
  262.         popmacport ();
  263.         }
  264.     } /*closeabout*/
  265.     
  266.     
  267. static boolean aboutwindowopen (void) {
  268.     
  269.     return (aboutwindow != nil);
  270.     } /*aboutwindowopen*/
  271.  
  272.  
  273. static boolean abouthandleevent (EventRecord ev, boolean *boxgoesaway) {
  274.  
  275.     /*
  276.     return true if the event is consumed, false if not.
  277.     
  278.     set boxgoesaway to true if the event should cause the about box to disappear.
  279.     */
  280.     
  281.     *boxgoesaway = false;
  282.     
  283.     switch (ev.what) {
  284.     
  285.         case keyDown: case autoKey: {
  286.         
  287.             register char ch = ev.message & charCodeMask;
  288.             
  289.             if ((ch == chreturn) || (ch == chenter)) {
  290.                 
  291.                 *boxgoesaway = true;
  292.                 
  293.                 return (true); /*event consumed*/
  294.                 }
  295.                 
  296.             break;
  297.             }
  298.             
  299.         case mouseDown:    {    
  300.             WindowPtr w;
  301.             
  302.             FindWindow (ev.where, &w);
  303.             
  304.             if (w != aboutwindow) /*event definitely not consumed*/
  305.                 return (false);
  306.                 
  307.             if (w == FrontWindow ())
  308.                 *boxgoesaway = true;
  309.             else
  310.                 SelectWindow (w);
  311.             
  312.             return (true); /*event consumed*/
  313.             }
  314.             
  315.         case updateEvt: {
  316.             register WindowPtr eventwindow = (WindowPtr) (ev.message);
  317.     
  318.             if (eventwindow != aboutwindow)
  319.                 return (false); /*event not consumed*/
  320.             
  321.             /*handle update, we might be using a screen saver*/
  322.             
  323.             pushmacport (eventwindow);
  324.             
  325.             BeginUpdate (eventwindow);
  326.             
  327.             drawabout (eventwindow);
  328.             
  329.             EndUpdate (eventwindow);
  330.             
  331.             popmacport ();
  332.                                 
  333.             return (true); /*event consumed, don't get rid of the about box*/
  334.             }
  335.             
  336.         case activateEvt:                                
  337.             return (true); /*event consumed, don't get rid of the about box*/
  338.         } /*switch*/
  339.     
  340.     return (false); /*event not consumed*/
  341.     } /*abouthandleevent*/
  342.  
  343.  
  344. void aboutcommand (void) {
  345.     
  346.     EventRecord ev;
  347.     boolean flexitabout = false;
  348.     
  349.     openabout (true);
  350.     
  351.     while (!flexitabout) {
  352.         
  353.         WaitNextEvent (everyEvent, &ev, 1, nil);
  354.         
  355.         if (!abouthandleevent (ev, &flexitabout)) { /*event not consumed by about box*/
  356.         
  357.             if (!maineventhandler (ev)) { /*user pressed cmd-period or Quit from file menu*/
  358.             
  359.                 flexitabout = true;
  360.                 }
  361.             }
  362.         } /*while*/
  363.     
  364.     closeabout (true);
  365.     } /*aboutcommand*/
  366.  
  367.  
  368.  
  369.  
  370.